﻿using System;
namespace Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="NoudeOsa", Namespace="http://producers.etoimik.xtee.riik.ee/producer/etoimik", Target=typeof(NoudeOsa))]
    public class NoudeOsaSerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected INoudeOsa clazz;
        
        public NoudeOsaSerializer(INoudeOsa clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.ObjektID!=null) {
                Writer.WriteStartElement("ObjektID");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "long");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdLong(((long)(clazz.ObjektID))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.JagamiseViisKL!=null) {
                Writer.WriteStartElement("JagamiseViisKL");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "long");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdLong(((long)(clazz.JagamiseViisKL))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.AlgusKP!=null) {
                Writer.WriteStartElement("AlgusKP");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "dateTime");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDateTime(((System.DateTime)(clazz.AlgusKP))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.LoppKP!=null) {
                Writer.WriteStartElement("LoppKP");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "dateTime");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDateTime(((System.DateTime)(clazz.LoppKP))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Noue!=null) {
                Writer.WriteStartElement("Noue");
                global::Xtee.Core.SerializationMetadata metaNoue = this.GetMetaData(clazz.Noue);
                Writer.WriteTypeAttribute(metaNoue.TypeQualifiedName.Namespace, metaNoue.TypeQualifiedName.Name);
                metaNoue.NewSerializer(clazz.Noue).WriteXml(Writer);
                Writer.WriteEndElement();
            }
            if (clazz.OsaNouded!=null) {
                Writer.WriteStartElement("OsaNouded");
                Writer.WriteTypeAttribute("http://schemas.xmlsoap.org/soap/encoding/", "Array");
                Writer.WriteArrayTypeAttribute("OsaNoue", "http://producers.etoimik.xtee.riik.ee/producer/etoimik", clazz.OsaNouded.Count);
                for (int x = 0; ((clazz.OsaNouded != null) 
                            && (x < clazz.OsaNouded.Count)); x = (x + 1)) {
                    if (clazz.OsaNouded[x]!=null) {
                        Writer.WriteStartElement("item");
                        global::Xtee.Core.SerializationMetadata metaOsaNouded = this.GetMetaData(clazz.OsaNouded[x]);
                        Writer.WriteTypeAttribute(metaOsaNouded.TypeQualifiedName.Namespace, metaOsaNouded.TypeQualifiedName.Name);
                        metaOsaNouded.NewSerializer(clazz.OsaNouded[x]).WriteXml(Writer);
                        Writer.WriteEndElement();
                    }
                }
                Writer.WriteEndElement();
            }
            if (clazz.SulgemiseKP!=null) {
                Writer.WriteStartElement("SulgemiseKP");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "dateTime");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdDateTime(((System.DateTime)(clazz.SulgemiseKP))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.KlientsysteemiID!=null) {
                Writer.WriteStartElement("KlientsysteemiID");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.KlientsysteemiID))).ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
            if (Reader.LocalName=="ObjektID") {
                if (Reader.IsElementNil()) {
                    throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>NoudeOsa>ObjektID");
                }
                clazz.ObjektID = new global::Xtee.Core.Schema.XsdLong(Reader.ReadElementString("ObjektID")).Value;
            }
            if (Reader.LocalName=="JagamiseViisKL") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.JagamiseViisKL = new global::Xtee.Core.Schema.XsdLong(Reader.ReadElementString("JagamiseViisKL")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="AlgusKP") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.AlgusKP = new global::Xtee.Core.Schema.XsdDateTime(Reader.ReadElementString("AlgusKP")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="LoppKP") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.LoppKP = new global::Xtee.Core.Schema.XsdDateTime(Reader.ReadElementString("LoppKP")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="Noue") {
                if ((Reader.IsElementNil() == false)) {
                    global::Xtee.Core.SerializationMetadata metaNoue = this.GetMetaData<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.INoue>(Reader, "Noue", "http://producers.etoimik.xtee.riik.ee/producer/etoimik");
                    clazz.Noue = metaNoue.NewEntity<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.INoue>();
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("Noue");
                        metaNoue.NewSerializer(clazz.Noue).ReadXml(Reader);
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="OsaNouded") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.OsaNouded = new System.Collections.Generic.List<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IOsaNoue>();
                    if ((Reader.IsEmptyElement == false)) {
                        Reader.ReadStartElement("OsaNouded");
                        for (; ((Reader.NodeType != System.Xml.XmlNodeType.EndElement) 
                                    && (Reader.LocalName == "item")); ) {
                            if ((Reader.IsElementNil() == false)) {
                                global::Xtee.Core.SerializationMetadata metaOsaNouded = this.GetMetaData<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IOsaNoue>(Reader, "OsaNoue", "http://producers.etoimik.xtee.riik.ee/producer/etoimik");
                                global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IOsaNoue item = metaOsaNouded.NewEntity<global::Producers.Etoimik.Xtee.Riik.Ee.Producer.Etoimik.IOsaNoue>();
                                clazz.OsaNouded.Add(item);
                                if ((Reader.IsEmptyElement == false)) {
                                    Reader.ReadStartElement("item");
                                    metaOsaNouded.NewSerializer(item).ReadXml(Reader);
                                    Reader.ReadEndElement();
                                }
                                else {
                                    Reader.Skip();
                                }
                            }
                            else {
                                clazz.OsaNouded.Add(null);
                                Reader.Skip();
                            }
                        }
                        Reader.ReadEndElement();
                    }
                    else {
                        Reader.Skip();
                    }
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="SulgemiseKP") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.SulgemiseKP = new global::Xtee.Core.Schema.XsdDateTime(Reader.ReadElementString("SulgemiseKP")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
            if (Reader.LocalName=="KlientsysteemiID") {
                if ((Reader.IsElementNil() == false)) {
                    clazz.KlientsysteemiID = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("KlientsysteemiID")).Value;
                }
                else {
                    Reader.Skip();
                }
            }
        }
    }
}
